﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Prism.ViewModel;
using System.Windows.Input;
using UserAccountModule.Commands;
using System.Windows;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Infrastructure.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Unity;
using Infrastructure.Account;

namespace UserAccountModule.ViewModels
{
    /// <summary>
    /// ViewModel for CatalogManagerMenuView.
    /// </summary>
    public class UserAccountMenuViewModel : NotificationObject
    {

        #region Fields
        IEventAggregator eventAggregator;
        IUnityContainer container;
        IRegionManager regionManager;
        string title;

        // Property variables

        #endregion

        #region Constructor
        /// <summary>
        /// Default constructor.
        /// </summary>
        public UserAccountMenuViewModel(IEventAggregator eventAggregator, IRegionManager regionManager, IUnityContainer container)
        {
            this.container = container;
            this.eventAggregator = eventAggregator;
            this.regionManager = regionManager;
            this.Initialize();
            if (ActiveAccount.Instance.TenNguoiDung != null)
            {
                Title = ActiveAccount.Instance.TenNguoiDung;
            }
            else
            {
                Title = ActiveAccount.Instance.TenTaiKhoan;
            }

            this.EditCommand = container.Resolve<EditCommand>(
                new ParameterOverrides 
                {
                    {"viewModel", this}
                }.OnType<EditCommand>()
            );

            this.LogoutCommand = container.Resolve<LogoutCommand>(
                new ParameterOverrides 
                {
                    {"viewModel", this}
                }.OnType<LogoutCommand>()
            );
        }
        #endregion

        #region Command Properties
        public ICommand EditCommand { get; set; }
        public ICommand LogoutCommand { get; set; }

        #endregion

        #region Administrative Properties
        public IRegionManager RegionManager
        {
            get { return regionManager; }
        }

        public IEventAggregator EventAggregator
        {
            get { return eventAggregator; }
        }

        public IUnityContainer Container
        {
            get { return container; }
        }

        public string Title
        {
            get { return title; }
            set
            {
                title = value;
                RaisePropertyChanged(() => this.Title);
            }
        }
        #endregion

        #region Event Handlers

        #endregion

        #region Private Methods
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        private void Initialize()
        {
            // Initialize the UI properties
        }
        #endregion
    }
}
